<template>
  <div>
    <!-- 子订单列表未选择 2018/3/7 11:44 zhangQ -->
    <Row>
      <i-col span="24">
        <Button type="primary" size="large" @click="bindSubOrderNoWithUser">
          <Icon type="ios-download-outline"></Icon>
          挑选为我们车队
        </Button>
      </i-col>
    </Row>
    <Row>
      <i-col span="24">
        <Table style="margin-top: 15px;overflow-x: auto" :columns="subOrderColumn" border :data="subOrderNotCheckData" @on-selection-change="subOrderCheck" height="600"></Table>
      </i-col>
    </Row>
  </div>
</template>

<script>
  import { bindSubOrderNoWithUser } from '@api/backEnd/mainOrder'
  import { getTrainTypeCN } from './trainTypeEnum'

  export default {
    name: 'sub-order-not-check',
    data () {
      let subOrderColumn = [
        {
          type: 'index',
          width: 60
        },
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          title: '火车车种类型',
          ellipsis: 'false',
          width: 150,
          render: (h, params) => {
            let trainType = params.row.trainType
            let trainTypeCN = getTrainTypeCN(trainType)
            return (<span>{trainTypeCN}</span>)
          }
        },
        {
          title: '箱号',
          ellipsis: 'false',
          width: 150,
          key: 'containerNoBody',
          render: (h, params) => {
            let containerNo = params.row.containerNoHead + params.row.containerNoBody
            return (<span>{containerNo}</span>)
          }
        },
        // {
        //   title: '司机',
        //   ellipsis: 'false',
        //   key: 'driverId',
        //   width: 200,
        //   render: (h, params) => {
        //     return (<span>{params.row.driverName}</span>)
        //   }
        // },
        // {
        //   title: '送货地址',
        //   ellipsis: 'false',
        //   width: 200,
        //   key: 'shippingAddress',
        //   render: (h, params) => {
        //     return (<span>{params.row.shippingAddress}</span>)
        //   }
        // },
        {
          title: '发货人',
          ellipsis: 'false',
          key: 'zkfhrmc',
          width: 250
        },
        {
          title: '收货人',
          ellipsis: 'false',
          key: 'zkshrmc',
          width: 250
        },
        {
          title: '品名',
          ellipsis: 'false',
          key: 'zkpmhz0',
          width: 150
        },
        {
          title: '接取送达费(元)',
          ellipsis: 'false',
          key: 'zkjf018',
          width: 120
        },
        {
          title: '送货地址',
          ellipsis: 'false',
          width: 200,
          key: 'shippingAddress',
          render: (h, params) => {
            return (<span>{params.row.shippingAddress}</span>)
          }
        },
        {
          title: '联系人',
          ellipsis: 'false',
          width: 100,
          key: 'contacts'
        },
        {
          title: '联系人电话',
          ellipsis: 'false',
          width: 150,
          key: 'contactsMobile'
        },
        // {
        //   title: '状态',
        //   ellipsis: 'false',
        //   width: 80,
        //   key: '',
        //   render: (h, params) => {
        //     let driverId = params.row.driverId
        //     if (driverId) {
        //       return (<span style="color:green">已派单</span>)
        //     } else {
        //       return (<span style="color:red">未派单</span>)
        //     }
        //   }
        // },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          width: 250,
          render: (h, params) => {
            let voucherImg = params.row.voucherImg
            let viewImg = (<i-button size="small" style="margin-right: 5px;">图片查看</i-button>)
            if (voucherImg) {
              viewImg = (<i-button type="primary" size="small" style="margin-right: 5px;" onClick={() => this.viewDetailImgAction(params.row)}>图片查看</i-button>)
            }
            let btnArray = []
            powerUtil.contains('orderListUnfinishedFleet') && btnArray.push(viewImg)
            return (btnArray)
          }
        }
      ]
      let selectionSubOrder = []
      let datas = { subOrderColumn, selectionSubOrder }
      return datas
    },
    props: {
      subOrderNotCheckData: {
        type: Array,
        default () {
          return []
        }
      },
      currentMainOrder: {
        type: Object,
        default () {
          return {}
        }
      }
    },
    computed: {},
    methods: {
      viewDetailImgAction (row) {
        this.$emit('viewDetailImg', row)
      },
      /**
       * TODO(选择子运单)
       * @auther zhangQ
       * @date 2018/3/26 19:30
       */
      subOrderCheck (selection) {
        console.log('row======', selection)
        this.selectionSubOrder = selection
      },
      bindSubOrderNoWithUser () {
        if (!(this.selectionSubOrder && this.selectionSubOrder.length > 0)) {
          this.$Notice.warning({
            title: '警告',
            desc: '请选择子运单'
          })
          return
        }
        let param = []
        this.selectionSubOrder.forEach((item) => {
          param.push({ subOrderNo: item.orderNo })
        })
        bindSubOrderNoWithUser(param)
          .then((res) => {
            if (+res.data.isSuccess === 1) {
              this.$Notice.success({
                title: '成功',
                desc: '绑定子运单成功'
              })
              this.$emit('refreshSource')
            } else {
              this.$Notice.error({
                title: '绑定失败',
                desc: res.data.res
              })
            }
          })
          .catch((res) => {
            this.$Notice.error({
              title: '绑定失败'
            })
          })
      }
    },
    created () {
    },
    mounted () {
    },
    components: {}
  }
</script>

<style scoped>

</style>
